package com.parkinginfo.manager;

/*
 * Author: Deepika Gohil
 * 
 */


import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import com.parkinginfo.manager.R;


public class ItemizedOverLays extends ItemizedOverlay<OverlayItem>{
	
	public ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	Context mContext;
	private int id = 0;

	public ItemizedOverLays(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
	}
	
	public ItemizedOverLays(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  mContext = context;
		}

	@Override
	protected OverlayItem createItem(int i) {
	  return mOverlays.get(i);
	}
	
	@Override
	public int size() {
	  return mOverlays.size();
	}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	protected boolean onTap(int index) 
	{
	  OverlayItem item = mOverlays.get(index);
	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
	  
	  id = index;
	  dialog.setTitle(item.getTitle());
	  dialog.setMessage(item.getSnippet());
      dialog.setCancelable(true);
      dialog.setNegativeButton("Cancel", onClickCancel);
      try{
      dialog.setPositiveButton("View Details", onClickProperty);
      }catch(Exception ex){
      }
	  dialog.show();
	  return true; 
	}
	

	public DialogInterface.OnClickListener onClickProperty = new DialogInterface.OnClickListener() 
	{
		public void onClick(DialogInterface dialog, int which) {
			Intent it = new Intent(mContext, ParkingDetailsActivity.class);
			it.putExtra("id", id);
			mContext.startActivity(it);
		}
	};
	
	public DialogInterface.OnClickListener onClickCancel = new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int which) {
		}
	};

}
